/*
 * @Author: your name
 * @Date: 2021-09-14 17:15:31
 * @LastEditTime: 2021-09-16 14:50:59
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \bigdate\src\ntils\loginfo\index.ts
 */

// 导出

import { proInfodata } from './loginfo'
import { format } from '../hooks'
import { ResourceFile } from './typs'

export interface logType{
    allloadTime:Number | any,
    domTime:Number | any,
    mobile:String,
    nowTime:Number,
    openTime:Number,
    requestTime:Number,
    whiteScreenTime:Number
}

export const sendSysInfo = (logInfo) => {
    let { allloadTime, domTime, mobile, nowTime, openTime, requestTime, whiteScreenTime } = JSON.parse(logInfo)
    return {
        allloadTime,
        domTime,
        mobile,
        nowTime: format(nowTime),
        openTime: format(openTime),
        requestTime,
        whiteScreenTime,
    }
}

export const sendOtherReac = (data) => {
    let filearr = {}
    let other = data.other
    let allsize = 0
    for (const item of ResourceFile) {
        filearr[item] = other.filter((items) => {
            if (items.name.indexOf(item) > 0) {
                return items
            }
        })
    }
    other.forEach(item => {
        allsize += item.size
    })
    return {
        allsize: AllSizeFun(allsize),
        len: other.length,
        filearr,
    }
}

function AllSizeFun(size) {
    let fileSize = ''
    if (size > 1024 * 1024) {
        fileSize = (Math.round(size * 100 / (1024 * 1024)) / 100).toString() + 'MB'
    } else {
        fileSize = (Math.round(size * 100 / 1024) / 100).toString() + 'KB'
    }  
    return fileSize     
}
